<template>
  <div class="cinema">
    <div class="theader">
      <img
        src=""
        alt=""
      />
      <div class="title">电影院</div>
      <div class="city-btn" @click="jump">
        城市定位 : {{ store.state.getinfo.name }}
      </div>
    </div>
    <div class="clist">
      <div class="cineam" v-for="(item, index) in cinemas" :key="'P1' + index">
        <div class="line">
          <p class="name">{{ item.name }}</p>
          <p class="price">￥ {{ guo(item.lowPrice) }} 起</p>
        </div>
        <div class="line">
          <p class="address">
            {{
              item.address.length > 20
                ? item.address.slice(0, 20) + "..."
                : item.address
            }}
          </p>
          <p class="distance">{{ km(item.Distance) }} km</p>
        </div>
      </div>
    </div>
  </div>
</template>
·

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";
import { useStore } from "vuex";
import { cinemasList } from "../axios/http";
import { CinemaType } from "../types/index";
const store = useStore();
const cinemas = ref<CinemaType[]>();
onMounted(async () => {
  let arr = await cinemasList(store.state.getinfo.id);
  console.log(arr.data.cinemas);
  cinemas.value = arr.data.cinemas;
});
// 钱过滤
const guo = (qian: number) => {
  return qian / 100;
};
// 公里数过滤
const km = (kms: number) => {
  return kms.toFixed(2);
};
const router = useRouter();
function jump() {
  router.push("/location");
}
</script>
<style lang="scss" scoped>
.theader {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  height: 60px;
  background: #fcfcfc;
  position: sticky;
  top: 0;
  left: 0;
  img {
    width: 28px;
    margin-left: 20px;
  }
  .title {
    color: #666;
  }
  .city-btn {
    margin-right: 20px;
    color: #ddd;
    background: #7232dd;
    padding: 3px 10px;
    border-radius: 5px;
  }
}
.clist {
  .cineam {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 15px;
    border-bottom: 1px solid #eee;
    height: 60px;
    .line {
      height: 24px;
    }
    .name {
      color: #191a1b;
      font-size: 15px;
      float: left;
    }
    .price {
      color: #ff5f16;
      font-size: 10px;
      float: right;
    }
    .address {
      color: #797d82;
      font-size: 12px;
      margin-top: 10px;
      float: left;
    }
    .distance {
      color: #797d82;
      font-size: 12px;
      margin-top: 5px;
      float: right;
    }
  }
}
</style>
